<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="${ctx!}/assets/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx!}/assets/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctx!}/assets/css/animate.css" rel="stylesheet">
    <link href="${ctx!}/assets/css/style.css?v=4.1.0" rel="stylesheet">

</head>

<body>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <form class="form-horizontal m-t" id="frm" method="post" action="${ctx!}/admin/device/edit">
                    <input type="hidden" id="id" name="id" value="${device.id}">
                    <input type="hidden" id="project_id" name="project_id" value="${project.id}">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">点位名称：</label>
                        <div class="col-sm-8">
                            <input id="name" name="name" class="form-control" type="text" value="${device.name}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">点位标签：</label>
                        <div class="col-sm-8">
                            <input id="tag" name="tag" class="form-control" type="text" value="${device.tag}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">点位类型：</label>
                        <div class="col-sm-8">
                            <input id="description" name="description" class="form-control" type="text"
                                   value="${device.description}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">智能网关：</label>
                        <div class="col-sm-8">
                            <select class="form_select form-control" id="gateway_id" name="gateway_id">
                                <#list gateways as gateway>
                                    <option value="${gateway.id}">${gateway.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">点位模板：</label>
                        <div class="col-sm-8">
                            <select class="form_select form-control" id="template_id" name="template_id">
                                <#list templates as template>
                                    <option value="${template.id}"
                                            <#if template.id==device.template.id>selected</#if>>${template.name} ${template.tag}</option>
                                </#list>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">通讯站号：</label>
                        <div class="col-sm-8">
                            <input id="communicationStation" name="communicationStation" class="form-control"
                                   type="text" value="${device.communicationStation}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">检测周期：</label>
                        <div class="col-sm-8">
                            <select class="form_select form-control" id="period" name="period">
                                <option value="300" <#if device.period==300>selected</#if>>5分钟</option>
                                <option value="600" <#if device.period==600>selected</#if>>10分钟</option>
                                <option value="900" <#if device.period==900>selected</#if>>15分钟</option>
                                <option value="1800" <#if device.period==1800>selected</#if>>30分钟</option>
                                <option value="3600" <#if device.period==3600>selected</#if>>1小时</option>
                            </select>
                        </div>
                    </div>


                    <div class="form-group">
                        <label class="col-sm-3 control-label">点位编号：</label>
                        <div class="col-sm-8">
                            <input id="number" name="number" class="form-control" type="text" value="${device.number}">

                        </div>
                    </div>


                    <div class="form-group">
                        <label class="col-sm-3 control-label">点位启用：</label>
                        <div class="col-sm-8">
                            <select class="form_select form-control" id="status" name="status">
                                <option value="1" <#if device.status==true>selected</#if>>开</option>
                                <option value="0" <#if device.status==false>selected</#if>>关</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">点位展示：</label>
                        <div class="col-sm-8">
                            <select class="form_select form-control" id="display" name="display">
                                <option value="0" <#if device.display==0>selected</#if>>隐藏</option>
                                <option value="1" <#if device.display==1>selected</#if>>展示</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-10 col-sm-offset-3 btn-box">
                            <button class="btn btn-primary" type="submit">确认</button>
                            <button class="btn btn-primary" onclick="back()" type="reset">取消</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<!-- 全局js -->
<script src="${ctx!}/assets/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctx!}/assets/js/bootstrap.min.js?v=3.3.6"></script>

<!-- 自定义js -->
<script src="${ctx!}/assets/js/content.js?v=1.0.0"></script>

<!-- jQuery Validation plugin javascript-->
<script src="${ctx!}/assets/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${ctx!}/assets/js/plugins/validate/messages_zh.min.js"></script>
<script src="${ctx!}/assets/js/plugins/layer/layer.min.js"></script>
<script src="${ctx!}/assets/js/plugins/layer/laydate/laydate.js"></script>
<script type="text/javascript">
    $(document).ready(function () {

        $("#frm").validate({
            rules: {
                name: {
                    required: true,
                },
                gateway_id: {
                    required: true,
                },
                tag: {
                    required: true,
                },
                template: {
                    required: false,
                },
                communicationStation: {
                    required: false,
                },
                period: {
                    required: false,
                },
                number: {
                    required: false,
                },
                status: {
                    required: true,
                },
                description: {
                    required: false,
                }
            },
            messages: {},
            submitHandler: function (form) {
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: "${ctx!}/admin/device/edit",
                    data: $(form).serialize(),
                    success: function (msg) {
                        layer.msg(msg.message, {time: 2000}, function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index);
                        });
                    }
                });
            }
        });
    });
</script>

</body>

</html>
